$(function(){
	$('#userGrid').datagrid({
	    method:'get',
		url:'findByParams',
	    toolbar:"#toolbar" ,
		rownumbers:true,
		pagination:true,
		striped:true,
		singleSelect:true,
	    columns:[[
			{field:'username',title:'登录名称',width:'15%',align:'center'},
			{field:'realname',title:'真实姓名',width:'15%',align:'center'},
			{field:'gender',title:'性别',width:'5%',align:'center'},
			{field:'postName',title:'职位',width:'15%',align:'center'},
			{field:'deptName',title:'部门',width:'15%',align:'center'},
			{field:'mobile',title:'联系方式',width:'10%',align:'center'},
			{field:'email',title:'邮箱',width:'15%',align:'center'},
			{field:'address',title:'地址',width:'9%',align:'center'}
	    ]]
	});
});

function query() {
	console.log($('#userfindform').serializeJson());
	$('#userGrid').datagrid('load', $('#userfindform').serializeJson());
}
function queryReset() {
	$('#userFind')[0].reset();
	$('#findDeptId').combo('setValue','');
}

function add() {
	$('#addUser').dialog('open');
}
function addCancel() {
	$('#addUser').dialog('close');
}

function addUser() {
	if($('#userForm').form('validate')){
		var obj = $('#userForm').serializeJson();
		obj.roleIds = $('#roleIds').combobox('getValues');
		$.ajax({
			url:'addUser', 
            type:'post',
            data:obj,
            success:function(data, statusText) { 
                if(data=='success'){
                	window.location.reload();
                }
            }
		});
	}
}

function update() {
	var rowData = $('#userGrid').datagrid('getSelected');
	if(rowData!=null){
		$('#updateWin').window({
			collapsible:false,
			minimizable:false,
			maximizable:false,
			title:'修改用户',
		    width:618,
		    height:310,
		    modal:true
		});
		$('#updateWin').window('refresh', 'toUpdateUser?userId='+rowData.userId);
	}
}

function updateCancel() {
	$('#updateWin').window('close');
}
function updateUser() {
	if($('#userUpdateForm').form('validate')){
		var obj = $('#userUpdateForm').serializeJson();
		obj.roleIds = $('#updateRoleIds').combobox('getValues');
		$.ajax({
			url:'updateUser', 
            type:'post',
            data:obj,
            success:function(data, statusText) { 
                if(data=='success'){
                	$('#userGrid').datagrid('reload');
                	$('#updateWin').window('close');
                }
            }
		});
	}
}